package com.biqee.action.base;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import com.biqee.model.common.ResultSet;
import com.biqee.util.JSONUtil;
import com.opensymphony.xwork.ModelDriven;

public abstract class BaseAjaxAction extends BaseAction implements ModelDriven {

	private static final long serialVersionUID = 3113804769913694578L;

	protected static final String GLOBLE_RESULT_JSON = "json";
	
	@Autowired
	private HttpServletRequest request;
	
	
	public String returnSuccess(Object obj){
		 ResultSet<Object> result = new ResultSet<Object>();
		 result.setData(obj);
		 request.setAttribute("json",JSONUtil.toJSONString(result)) ;
	    	return GLOBLE_RESULT_JSON;
	}


	
	
	
	public String returnError(Exception e){
		 ResultSet<Object> result = new ResultSet<Object>();
		 result.setSuccess(false);
		 result.setMessage(e.getMessage());
//		if(e instanceof BusinessUnCheckedException){
//			BusinessUnCheckedException bussionException = (BusinessUnCheckedException)e;
//			result.setCode(bussionException.getErrorCode());
//		}
		 request.setAttribute("json",JSONUtil.toJSONString(result)) ;
	    	return GLOBLE_RESULT_JSON;
		 
	}


}
